package ttc.sftp.adapter;

import java.util.List;
import java.util.Vector;

import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.SftpException;

import ttc.sftp.R;
import ttc.sftp.data.LocalData;
import ttc.sftp.data.VFile;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import ttc.sftp.data.*;

public class RemoteFileAdapter extends BaseAdapter {
	public Vector<SFile> vectorFiles;
	private RemoteFile remoteFile;
	LayoutInflater inflater;


	
	public RemoteFileAdapter(LayoutInflater inflater,ChannelSftp channel) throws SftpException{
		this.inflater=inflater;
		remoteFile= new RemoteFile("", channel);
		vectorFiles = remoteFile.getVectorFile();
	}
	
	public SFile getFile(){
		return remoteFile.getFile();
	}
	
	public void setPath(String path,ChannelSftp channel) throws SftpException{
		vectorFiles.clear();
		remoteFile=new RemoteFile(path, channel);
		vectorFiles=remoteFile.getVectorFile();
		
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return vectorFiles.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return vectorFiles.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View row = convertView;
		if (row == null) {
			row = inflater.inflate(R.layout.list_item, parent, false);
		}
		ImageView icon= (ImageView)row.findViewById(R.id.list_item_icon);
		TextView name = (TextView) row.findViewById(R.id.list_item_name);
		
		Object obj = vectorFiles.elementAt(position);
		
		if(((com.jcraft.jsch.ChannelSftp.LsEntry)obj).getAttrs().isDir())
			icon.setImageResource(R.drawable.iconfolder);
		else
			icon.setImageResource(R.drawable.iconlocal);
		name.setText(((com.jcraft.jsch.ChannelSftp.LsEntry)obj).getFilename());
		return row;
		
		
		
		
	}

}
